<?php
namespace app\index\controller;
use think\Controller;
use think\Request;
use think\Cookie;
class Goods extends Common
{
    public function index()
    {
		return view('index/index');		
	}
	public function goods(){
		/*$pageNumber=1;
		$pageSize=10;
		$isSaleOnline=true;
		if(input('?get.pageNumber')){
			$pageNumber=input('get.pageNumber');
		}
		if(input('?get.pageSize')){
			$pageSize=input('get.pageSize');
		}
		if(input('?get.isSaleOnline')){
			$isSaleOnline=input('get.isSaleOnline');
		}*/
		$url=config('tdwApi')."/product/findProductList.jhtml";
		$res=$this->http($url);
		$res=json_decode($res[0],true);	
		if($res['code']==1){
			$data=$res['data'];
			/*$totalPages=$res['data']['totalPage'];
			$pageNumber=$res['data']['pageNumber'];
			$total_arr=array();
			for($i=1; $i<=$totalPages; $i++){
				$total_arr[]=$i;
			}*/
			return view('goods/product',[
				'act'=>'product',
				'data'=>$data,
				/*'total_arr'=>$total_arr,
				'totalPages'=>$totalPages,
				'pageNumber'=>$pageNumber,*/
			]);
		}else{
			$this->error('出错了,请稍后重试',url('index/Index/index'),'',3);				
		}				
	}
	public function productHtml(){
		$url = config('tdwApi')."/product/getProductIds.jhtml";
		$res=$this->http($url);
		$res=json_decode($res[0],true);
		if($res['code']==1)
		{
			$arr=$res['data']['productIdArray'];
			foreach ($arr as $value) {
				$productId=$value['productId'];
				$data = $this->productCreateHtml($productId);
			}			
			$data['code']=200;
			$data['msg']="生成成功";			
		}else{
			$data['code']=500;
			$data['msg']="生成失败";			
		}
		echo json_encode($data);			
	}
	public function productCreateHtml($productId){
		$url=config('tdwApi')."/product/findProductDetail.jhtml?productId=$productId";
		$res=$this->http($url);
		$res=json_decode($res[0],true);	
		if($res['code']==1){
			$data=$res['data'];
			$this->assign('act','product');		
			$this->assign('data',$data);			
			$this->buildHtml($productId,'./product/',"goods/detail",'utf8');
		}
	}
	public function deposit(){
        if(Cookie::has('userInfo')==false) {
            $this->error('对不起,您还没有登录!请先登录再进行浏览',url('index/Login/login',['jump'=>'deposit']),'',3);
        }else{
			$userInfo=Cookie::get('userInfo');
			Cookie::set('userInfo',$userInfo,7200);			
			$url=config('tdwApi')."/ordersPool/listFromIndex.jhtml?type=deposit";
			$res=$this->http($url);
			$res=json_decode($res[0],true);	
			if($res['code']==1){
				$data=$res['data'];
				return view('goods/deposit',['data'=>$data]);
			}else{
				$this->error('当前暂无可抢购订单,请关注信息公告',url('index/Index/notice'),'',3);				
			}
		}
	}
	public function dividend(){
        if(Cookie::has('userInfo')==false) {
            $this->error('对不起,您还没有登录!请先登录再进行浏览',url('index/Login/login',['jump'=>'dividend']),'',3);
        }else{
			$userInfo=Cookie::get('userInfo');
			Cookie::set('userInfo',$userInfo,7200);
			$url=config('tdwApi')."/ordersPool/listFromIndex.jhtml?type=bonus";
			$res=$this->http($url);
			$res=json_decode($res[0],true);	
			if($res['code']==1){
				$data=$res['data'];
				return view('goods/dividend',['data'=>$data]);
			}else{
				$this->error('当前暂无可抢购订单,请关注信息公告',url('index/Index/notice'),'',3);				
			}
			
		}
	}
	public function customize(){
		return view('goods/customize');
	}
	public function customizePost(){
		$data['specifications']=input('post.specifications');
		$data['category']=input('post.category');
		$data['position']=input('post.position');
		$data['traffic']=input('post.traffic');
		$data['quantity']=input('post.quantity');
		$data['phone']=input('post.phone');
		$data['description']=input('post.description');
		$url=config('tdwApi')."/customization/save.jhtml";
		$res=$this->https_post($url,$data);
		return $res;		
	}
	public function detail(){
		$productId=input('get.id');
		$url=config('tdwApi')."/product/findProductDetail.jhtml?productId=$productId";
		$res=$this->http($url);
		$res=json_decode($res[0],true);	
		if($res['code']==1){
			$data=$res['data'];
			//dump($data);exit;
			return view('goods/detail',['data'=>$data]);
		}else{
			$this->error('出错了,请稍后重试',url('index/Index/index'),'',3);				
		}		
	}
	public function depositDetail(){
		$productId=input('get.id');
		$poolQuantity=input('get.poolQuantity');
		$url=config('tdwApi')."/product/findProductDetail.jhtml?productId=$productId";
		$res=$this->http($url);
		$res=json_decode($res[0],true);	
		if($res['code']==1){
			$data=$res['data'];
			return view('goods/depositDetail',['data'=>$data,'poolQuantity'=>$poolQuantity]);
		}else{
			$this->error('出错了,请稍后重试',url('index/Index/index'),'',3);				
		}
		
	}
	public function dividendDetail(){
		$productId=input('get.id');
		$url=config('tdwApi')."/product/findProductDetail.jhtml?productId=$productId";
		$res=$this->http($url);
		$res=json_decode($res[0],true);	
		if($res['code']==1){
			$data=$res['data'];
			return view('goods/dividendDetail',['data'=>$data]);
		}else{
			$this->error('出错了,请稍后重试',url('index/Index/index'),'',3);				
		}
		
	}
	public function integralList(){
        if(Cookie::has('userInfo')==false) {
            $this->error('对不起,您还没有登录!请先登录再进行浏览',url('index/Login/login',['jump'=>'Integral']),'',3);
        }else{
			$userInfo=Cookie::get('userInfo');
			Cookie::set('userInfo',$userInfo,7200);
			$type=input('get.type');			
			$url=config('tdwApi')."/product/getPointProducts.jhtml?type=$type";
			$res=$this->http($url);
			$res=json_decode($res[0],true);	
			if($res['code']==1){
				$data=$res['data'];
				return view('goods/integralList',['data'=>$data]);
			}else{
				$this->error('出错了请稍后重试',url('index/Member/index'),'',3);				
			}
		}		
	}
	public function integralDetail(){
		$productId=input('get.id');
		$url=config('tdwApi')."/product/findProductDetail.jhtml?productId=$productId";
		$res=$this->http($url);
		$res=json_decode($res[0],true);	
		if($res['code']==1){
			$data=$res['data'];
			return view('goods/integralDetail',['data'=>$data]);
		}else{
			$this->error('出错了,请稍后重试',url('index/Member/index'),'',3);				
		}
		
	}	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}
